﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
using WxTenpay.Common;
using WxTenpay.Service.Model;


namespace WxTenpay.Service.Service
{
    public class SysUser : BaseService<SysUserEntity>, ISysUser
    {
        /// <summary>
        /// 获得列表——分页
        /// </summary>
        /// <param name="parm">PageParm</param>
        /// <returns></returns>
        public PageModel.Page<SysUserEntity> GetRolePages(PageModel.PageParm parm)
        {

            var expression = Expressionable.Create<SysUserEntity>();
            var query = parm.data.ToString().ToObject();

            if (!query["Name"].IsEmpty()) expression.And(u => u.Name.Contains(query["Name"].ToString()));

            if (!query["IsDel"].IsEmpty()) expression.And(u => u.IsDel == query["IsDel"].ToInt());
            if (!query["UserName"].IsEmpty()) expression.And(u => u.UserName.Contains(query["UserName"].ToString()));

            return Db.Queryable<SysUserEntity, SysRoleEntity>((u, r) => new JoinQueryInfos(JoinType.Left, u.RoleGuId == r.GuId)).Where(expression.ToExpression())
                .Select((u, r) =>
                new SysUserEntity
                {
                    role = r,
                    CreateTime = u.CreateTime,
                    GuId = u.GuId,
                    Id = u.Id,
                    RoleGuId = u.RoleGuId,
                    IsDel = u.IsDel,
                    Name = u.Name,
                    NickName = u.NickName,
                    UserName = u.UserName,
                    Password = u.Password,
                    CompanyGuId = u.CompanyGuId,
                    DepartmentGuId = u.DepartmentGuId

                }
                )
                .ToPage(parm.page, parm.limit);

        }

    }
}
